//
//  CX_DataDownloadTools.m
//  UILesson17_imageDownloader
//
//  Created by lanou3g on 15/10/29.
//  Copyright (c) 2015年 lanou3g. All rights reserved.
//

#import "CX_DataDownloadTools.h"

@implementation CX_DataDownloadTools

+(void)downloadDataWithURL:(NSString *)urlStr andMethod:(NSString *)method andBody:(NSString *)body andBlock:(optionBlock)block
{
    NSURL *url = [NSURL URLWithString:urlStr];
    
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc]initWithURL:url];
    //有没有更好的方式可以
    if ([method isEqualToString:@"POST"]||[method isEqualToString:@"post"]) {
        //这里就添加以下POST方式需要设置的东西
        [request setHTTPMethod:@"POTH"];
        [request setHTTPBody:[body dataUsingEncoding:NSUTF8StringEncoding]];
        
    }
    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
        block(data);
    }];
}



@end
